package com.mytest.test.until;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.mytest.test.mapper.StudentsBatchMapper;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * mybatis-plus自定义sql模板，自定义批量更新或插入
 * 在springboot 启动时动态加载自定义的sql
 * @author chengxucai
 */

@Component
public class MysqlInjector extends DefaultSqlInjector {
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
        //1.获取注入的所有方法（父类扫描所有的mapper，提取泛型模型不为空的）
        List<AbstractMethod> methodList = super.getMethodList(mapperClass);
        if(mapperClass.equals(StudentsBatchMapper.class)){
            //2.对注入方法加上自定义的插入修改方法
            methodList.add(new MysqlInsertOrUpdateBath());
        }
        return methodList;
    }
}

